package com.xiaomaoguai.fcp.pre.kepler.router.rpc.server.servlet.registration;


import javax.servlet.FilterConfig;
import javax.servlet.Registration;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;

import com.xiaomaoguai.fcp.pre.kepler.router.rpc.server.servlet.core.NettyContext;

import java.util.Collections;
import java.util.Enumeration;
import java.util.Map;
import java.util.Set;

import static com.google.common.base.Preconditions.checkNotNull;

/**
 * 实现Filter和Servlet的动态注册的抽象类
 */
class AbstractNettyRegistration implements Registration, Registration.Dynamic, ServletConfig, FilterConfig {

	private final String name;

	private final String className;

	private final NettyContext context;

	protected boolean asyncSupported;

	protected AbstractNettyRegistration(String name, String className, NettyContext context) {
		this.name = checkNotNull(name);
		this.className = checkNotNull(className);
		this.context = checkNotNull(context);
	}

	@Override
	public void setAsyncSupported(boolean isAsyncSupported) {
		asyncSupported = isAsyncSupported;
	}

	@Override
	public String getName() {
		return name;
	}

	@Override
	public String getClassName() {
		return className;
	}

	@Override
	public boolean setInitParameter(String name, String value) {
		return false;
	}

	@Override
	public String getInitParameter(String name) {
		return null;
	}

	@Override
	public Set<String> setInitParameters(Map<String, String> initParameters) {
		return Collections.emptySet();
	}

	@Override
	public Map<String, String> getInitParameters() {
		return Collections.emptyMap();
	}

	//Init Parameter相关的方法，因为没用到，暂时不实现

	@Override
	public String getFilterName() {
		return name;
	}

	@Override
	public String getServletName() {
		return name;
	}

	@Override
	public ServletContext getServletContext() {
		return context;
	}

	@Override
	public Enumeration<String> getInitParameterNames() {
		return Collections.emptyEnumeration();
	}

	NettyContext getNettyContext() {
		return context;
	}
}
